package crm.clientManagement.managedbean;

import crm.clientManagement.entity.CompanyEntity;
import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;

@ManagedBean
@ViewScoped
public class CreateNewResultManagedBean implements Serializable {

    private CompanyEntity company;
    private String message;
    private String address;
    private String contact;

    public CreateNewResultManagedBean() {
    }

    public void initView(PhaseEvent event) {
        if (company == null) {
            company = (CompanyEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("newCompany");
        }
        address = company.getAddress().getStreetName()+", "+company.getAddress().getCity()+", "+company.getAddress().getPostCode();
        contact = company.getContactPersonTitle()+". "+company.getContactPersonName();
        message = "New company has been created. ID: "+String.valueOf(company.getId());
    }
    
    public void goBack() throws IOException{
        FacesContext.getCurrentInstance().getExternalContext().redirect("./deleteCompany.xhtml");
    }

    public CompanyEntity getCompany() {
        return company;
    }

    public void setCompany(CompanyEntity company) {
        this.company = company;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the contact
     */
    public String getContact() {
        return contact;
    }

    /**
     * @param contact the contact to set
     */
    public void setContact(String contact) {
        this.contact = contact;
    }
}
